//
//  RCChangePointsDetailCell.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-11-24.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCChangePointsDetailCell.h"
#import "NSString+NSString_Ex_.h"
#import "UIColor-Expanded.h"
#import "CommonDefines.h"
#import "RCChangePointsDetailDataModel.h"
#import "UIImageView+WebCache.h"
#import "TTTAttributedLabel.h"
#import "NSAttributedString+LVAddition.h"

#define kDefaultimageFile        @"image_recommendFood_image_bg.png"
#define kImageCommitButton       @"login_btn.png"
#define kStartActiveImageFile    @"image_start_active.png"
#define kStartInActiveImageFile  @"image_merchant_inactive.png"
#define kLineImageFile           @"image_order_line.png"

@interface RCChangePointsDetailPicHeaderCell()

@property(nonatomic,retain)UILabel *nameLabel;
@property(nonatomic,retain)UILabel *remainLabel;
@property(nonatomic,retain)UIImageView *startImageView1;
@property(nonatomic,retain)UIImageView *startImageView2;
@property(nonatomic,retain)UIImageView *startImageView3;
@property(nonatomic,retain)UIImageView *startImageView4;
@property(nonatomic,retain)UIImageView *startImageView5;

@property(nonatomic,retain)UIImageView *defaultImageView;
@property(nonatomic,retain)UIImageView *picImageView;

@property(nonatomic,retain)UILabel *changePointsLabel;
@property(nonatomic,retain)UILabel *pointsLabel;
@property(nonatomic,retain)UILabel *priceLabel;
@property(nonatomic,retain)UILabel *codeNumLabel;
@property(nonatomic,retain)UILabel *changeTimeLabel;

@property(nonatomic,retain)UIButton *orderButton;
@property(nonatomic,retain)UIView   *lineView;

@end

@implementation RCChangePointsDetailPicHeaderCell

@synthesize nameLabel = _nameLabel;
@synthesize remainLabel = _remainLabel;
@synthesize startImageView1 = _startImageView1;
@synthesize startImageView2 = _startImageView2;
@synthesize startImageView3 = _startImageView3;
@synthesize startImageView4 = _startImageView4;
@synthesize startImageView5 = _startImageView5;

@synthesize defaultImageView = _defaultImageView;
@synthesize picImageView = _picImageView;

@synthesize changePointsLabel = _changePointsLabel;
@synthesize pointsLabel = _pointsLabel;
@synthesize priceLabel = _priceLabel;
@synthesize codeNumLabel = _codeNumLabel;
@synthesize changeTimeLabel = _changeTimeLabel;

@synthesize orderButton = _orderButton;
@synthesize lineView = _lineView;

@synthesize delegate = _delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
        
    }
    return self;
}

-(void)dealloc{
    
    self.delegate = nil;
    
    self.nameLabel = nil;
    self.remainLabel = nil;
    
    self.startImageView1 = nil;
    self.startImageView2 = nil;
    self.startImageView3 = nil;
    self.startImageView4 = nil;
    self.startImageView5 = nil;
    
    self.defaultImageView = nil;
    self.picImageView = nil;
    
    self.changePointsLabel = nil;
    self.pointsLabel = nil;
    
    self.priceLabel = nil;
    self.codeNumLabel = nil;
    self.changeTimeLabel = nil;
    
    self.orderButton = nil;
    self.lineView = nil;
    [super dealloc];
}

-(void)createPlaceHolderView{
    
    _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 14, 100, 16)];
    _nameLabel.backgroundColor = [UIColor clearColor];
    _nameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    _nameLabel.textColor = [UIColor colorWithHex:0xff505050];
    [self addSubview:_nameLabel];
    
    _remainLabel = [[UILabel alloc]initWithFrame:CGRectMake(110, 18, 100, 12)];
    _remainLabel.backgroundColor = [UIColor clearColor];
    _remainLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _remainLabel.textColor = [UIColor colorWithHex:0xff505050];
    [self addSubview:_remainLabel];
    
    _startImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(231, 16, 14, 14)];
    _startImageView1.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView1];
    
    _startImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(246, 16, 14, 14)];
    _startImageView2.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView2];
    
    _startImageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(261, 16, 14, 14)];
    _startImageView3.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView3];
    
    _startImageView4 = [[UIImageView alloc]initWithFrame:CGRectMake(276, 16, 14, 14)];
    _startImageView4.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView4];
    
    _startImageView5 = [[UIImageView alloc]initWithFrame:CGRectMake(291, 16, 14, 14)];
    _startImageView5.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView5];
    
    _defaultImageView = [[UIImageView alloc]initWithFrame:CGRectMake(14, 36, 292, 124)];
    _defaultImageView.backgroundColor = [UIColor clearColor];
    UIImage *defaultImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kDefaultimageFile ofType:nil]];
    defaultImage = [defaultImage resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    [_defaultImageView setImage:defaultImage];
    [self addSubview:_defaultImageView];
    
    _picImageView = [[UIImageView alloc]initWithFrame:CGRectMake(17, 39, 286, 118)];
    _picImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:_picImageView];
    
    _changePointsLabel = [[UILabel alloc]initWithFrame:CGRectMake(18, 172, 100, 12)];
    _changePointsLabel.backgroundColor = [UIColor clearColor];
    _changePointsLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _changePointsLabel.textColor = [UIColor colorWithHex:0xff737272];
    _changePointsLabel.text = @"兑换积分：";
    
    CGSize size = [_changePointsLabel.text sizeWithFont:_changePointsLabel.font constrainedToSize:CGSizeMake(200, 20)];
    _changePointsLabel.frame = CGRectMake(18, 172, size.width, 12);
    [self addSubview:_changePointsLabel];
    
    CGFloat originX = CGRectGetMaxX(_changePointsLabel.frame);
    CGFloat width = 165-size.width;
    _pointsLabel = [[UILabel alloc]initWithFrame:CGRectMake(originX, 171, width, 13)];
    _pointsLabel.backgroundColor = [UIColor clearColor];
    _pointsLabel.textColor = [UIColor colorWithHex:0xfffe8301];
    _pointsLabel.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    [self addSubview:_pointsLabel];
    
    _priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, 172, 140, 13)];
    _priceLabel.backgroundColor = [UIColor clearColor];
    _priceLabel.textColor = [UIColor colorWithHex:0xff737272];
    _priceLabel.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    [self addSubview:_priceLabel];
    
    _codeNumLabel = [[UILabel alloc]initWithFrame:CGRectMake(18, 190, 150, 13)];
    _codeNumLabel.backgroundColor = [UIColor clearColor];
    _codeNumLabel.textColor = [UIColor colorWithHex:0xff737272];
    _codeNumLabel.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    [self addSubview:_codeNumLabel];
    
    _changeTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, 190, 140, 13)];
    _changeTimeLabel.backgroundColor = [UIColor clearColor];
    _changeTimeLabel.textColor = [UIColor colorWithHex:0xff737272];
    _changeTimeLabel.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    [self addSubview:_changeTimeLabel];
    
    UIImage *orderImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kImageCommitButton ofType:nil]];
    _orderButton = [[UIButton alloc]initWithFrame:CGRectMake(18, 216, 284, 35)];
    _orderButton.backgroundColor = [UIColor clearColor];
    [_orderButton setBackgroundImage:orderImage forState:UIControlStateNormal];
    [_orderButton setBackgroundImage:orderImage forState:UIControlStateHighlighted];
    [_orderButton addTarget:self action:@selector(orderButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_orderButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_orderButton setTitle:@"立即兑换" forState:UIControlStateNormal];
    _orderButton.titleLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    [self addSubview:_orderButton];
    
    _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 259, 320, 1)];
    _lineView.backgroundColor = [UIColor colorWithHex:0xfff99176];
    [self addSubview:_lineView];
}

-(void)bindData:(RCChangePointsDetailDataModel *)dataModel{
    if (nil == dataModel) {
        return;
    }
    
    _nameLabel.hidden = YES;
    CGFloat width = 14;
    if (![NSString stringIsNullOrEmpty:dataModel.title]) {
        _nameLabel.hidden = NO;
        _nameLabel.text = dataModel.title;
        CGSize size = [_nameLabel.text sizeWithFont:_nameLabel.font constrainedToSize:CGSizeMake(200, 20)];
        CGRect rect = _nameLabel.frame;
        rect.size.width = size.width;
        _nameLabel.frame = rect;
        
        width = CGRectGetMaxX(_nameLabel.frame)+7;
    }
    
    _remainLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:dataModel.remain]) {
        _remainLabel.hidden = NO;
        _remainLabel.text = [NSString stringWithFormat:@"剩余%@件",dataModel.remain];
        CGRect rect = _remainLabel.frame;
        rect.origin.x = width;
        _remainLabel.frame = rect;
    }
    
    _startImageView1.hidden = YES;
    _startImageView2.hidden = YES;
    _startImageView3.hidden = YES;
    _startImageView4.hidden = YES;
    _startImageView5.hidden = YES;
    
    NSInteger score = dataModel.score;
    if (score > 0) {
        
        _startImageView1.hidden = NO;
        _startImageView2.hidden = NO;
        _startImageView3.hidden = NO;
        _startImageView4.hidden = NO;
        _startImageView5.hidden = NO;
        
        NSString *resourcePath = [[NSBundle mainBundle]resourcePath];
        UIImage *activeImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartActiveImageFile]];
        UIImage *inactiveImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartInActiveImageFile]];
        [_startImageView1 setImage:score > 0 ? activeImage : inactiveImage];
        [_startImageView2 setImage:score > 1 ? activeImage : inactiveImage];
        [_startImageView3 setImage:score > 2 ? activeImage : inactiveImage];
        [_startImageView4 setImage:score > 3 ? activeImage : inactiveImage];
        [_startImageView5 setImage:score > 4 ? activeImage : inactiveImage];
    }
    
    CGFloat height = 30;
    _defaultImageView.hidden = YES;
    _picImageView.hidden = YES;
    if (![NSString stringIsNullOrEmpty:dataModel.thumb]) {
        _defaultImageView.hidden = NO;
        _picImageView.hidden = NO;
        
        height +=6;
        [_picImageView setImageWithURL:[NSURL URLWithString:dataModel.thumb] placeholderImage:nil];
        
        height +=124;
    }
    
    height +=12;
    
    CGFloat orightX = 18;
    _changePointsLabel.hidden = YES;
    _pointsLabel.hidden = YES;
    
    NSInteger infoCount = 0;
    
    if (![NSString stringIsNullOrEmpty:dataModel.points]) {
        _changePointsLabel.hidden = NO;
        _pointsLabel.hidden = NO;
        
        _pointsLabel.text = dataModel.points;
        orightX = 180;
        
        CGRect changeRect = _changePointsLabel.frame;
        changeRect.origin.y = height;
        _changePointsLabel.frame = changeRect;
        
        CGRect pointRect = _pointsLabel.frame;
        pointRect.origin.y = height;
        _pointsLabel.frame = pointRect;
        
        infoCount ++;
    }
    
    _priceLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:dataModel.price]) {
        _priceLabel.hidden = NO;
        _priceLabel.text = [NSString stringWithFormat:@"参考价：￥%@",dataModel.price];
        
        CGRect rect = _priceLabel.frame;
        rect.origin.x = orightX;
        rect.origin.y = height;
        _priceLabel.frame = rect;
        
        if (orightX == 18) {
            orightX = 180;
        }else if (orightX == 180){
            orightX = 18;
        }
        
        infoCount ++;
        if (infoCount > 0 && infoCount %2 == 0) {
            height +=18;
        }
    }
    
    _codeNumLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:dataModel.codeNumber]) {
        _codeNumLabel.hidden = NO;
        _codeNumLabel.text = [NSString stringWithFormat:@"兑换编码：%@",dataModel.codeNumber];
        
        CGRect rect = _codeNumLabel.frame;
        rect.origin.x = orightX;
        rect.origin.y = height;
        _codeNumLabel.frame = rect;
        
        if (orightX == 18) {
            orightX = 180;
        }else if (orightX == 180){
            orightX = 18;
        }
        
        infoCount ++;
        if (infoCount > 0 && infoCount %2 == 0) {
            height +=18;
        }
    }
    
    _changeTimeLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:dataModel.changetimes]) {
        _changeTimeLabel.hidden = NO;
        _changeTimeLabel.text = [NSString stringWithFormat:@"兑换次数：%@",dataModel.changetimes];
        
        CGRect rect = _changeTimeLabel.frame;
        rect.origin.x = orightX;
        rect.origin.y = height;
        _changeTimeLabel.frame = rect;
        
        infoCount ++;
        if (infoCount > 0 && infoCount %2 == 0) {
            height +=12;
        }
        
    }
    
    height +=13;
    
    CGRect buttonRect = _orderButton.frame;
    buttonRect.origin.y = height;
    _orderButton.frame = buttonRect;
    
    height +=35;
    height +=8;
    
    CGRect lineRect = _lineView.frame;
    lineRect.origin.y = height;
    _lineView.frame = lineRect;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

+(CGFloat)getCellHeight:(RCChangePointsDetailDataModel *)dataModel{
    if (nil == dataModel) {
        return 0.0f;
    }
    
    CGFloat height = 30;
    if (![NSString stringIsNullOrEmpty:dataModel.thumb]) {
        height +=130;
    }
    
    CGFloat infoCount = 0;
    if (![NSString stringIsNullOrEmpty:dataModel.points]) {
        infoCount ++;
    }
    
    if (![NSString stringIsNullOrEmpty:dataModel.price]) {
        infoCount ++;
    }
    
    if (![NSString stringIsNullOrEmpty:dataModel.codeNumber]) {
        infoCount ++;
    }
    
    if (![NSString stringIsNullOrEmpty:dataModel.changetimes]) {
        infoCount ++;
    }
    
    if (infoCount > 0 && infoCount <=2) {
        height +=24;
    }else if (infoCount > 2){
        height +=42;
    }
    
    height +=48;
    height +=9;
    
    return height;
}

-(void)orderButtonClicked{
    if (_delegate && [_delegate respondsToSelector:@selector(gotoChangeOrderPage)]) {
        [_delegate gotoChangeOrderPage];
    }
}

@end

@interface RCChangePointsDetailReviewCell()

@property(nonatomic,retain)UILabel *themeNameLabel;
@property(nonatomic,retain)UILabel *userNameLabel;
@property(nonatomic,retain)TTTAttributedLabel *contentLabel;
@property(nonatomic,retain)UILabel *timeLabel;

@property(nonatomic,retain)UIImageView *startImageView1;
@property(nonatomic,retain)UIImageView *startImageView2;
@property(nonatomic,retain)UIImageView *startImageView3;
@property(nonatomic,retain)UIImageView *startImageView4;
@property(nonatomic,retain)UIImageView *startImageView5;

@property(nonatomic,retain)UIImageView *lineImageView;

@end

@implementation RCChangePointsDetailReviewCell

@synthesize themeNameLabel = _themeNameLabel;
@synthesize userNameLabel = _userNameLabel;
@synthesize contentLabel = _contentLabel;
@synthesize timeLabel = _timeLabel;
@synthesize startImageView1 = _startImageView1;
@synthesize startImageView2 = _startImageView2;
@synthesize startImageView3 = _startImageView3;
@synthesize startImageView4 = _startImageView4;
@synthesize startImageView5 = _startImageView5;

@synthesize lineImageView = _lineImageView;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
    }
    return self;
}

-(void)dealloc{
    self.themeNameLabel = nil;
    self.userNameLabel = nil;
    self.contentLabel = nil;
    self.timeLabel = nil;
    
    self.startImageView1 = nil;
    self.startImageView2 = nil;
    self.startImageView3 = nil;
    self.startImageView4 = nil;
    self.startImageView5 = nil;
    
    self.lineImageView = nil;
    
    [super dealloc];
}

-(void)createPlaceHolderView{
    
    _themeNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 7, 220, 16)];
    _themeNameLabel.backgroundColor = [UIColor clearColor];
    _themeNameLabel.textColor = [UIColor colorWithHex:0xfffe8301];
    _themeNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    [self addSubview:_themeNameLabel];
    
    _userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 26, 280, 16)];
    _userNameLabel.backgroundColor = [UIColor clearColor];
    _userNameLabel.textColor = [UIColor colorWithHex:0xff737272];
    _userNameLabel.font = [UIFont fontWithName:kFontNameHelvetica size:16];
    [self addSubview:_userNameLabel];
    
    _startImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(14, 45, 14, 14)];
    _startImageView1.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView1];
    
    _startImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(29, 45, 14, 14)];
    _startImageView2.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView2];
    
    _startImageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(44, 45, 14, 14)];
    _startImageView3.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView3];
    
    _startImageView4 = [[UIImageView alloc]initWithFrame:CGRectMake(59, 45, 14, 14)];
    _startImageView4.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView4];
    
    _startImageView5 = [[UIImageView alloc]initWithFrame:CGRectMake(74, 45, 14, 14)];
    _startImageView5.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView5];
    
    _contentLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(14, 62, 292, 16)];
    _contentLabel.backgroundColor = [UIColor clearColor];
    _contentLabel.textColor = [UIColor colorWithHex:0xff737272];
    _contentLabel.font = [UIFont systemFontOfSize:16];
    _contentLabel.numberOfLines = 0;
    _contentLabel.leading = 6;
    [self addSubview:_contentLabel];
    
    _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 81, 270, 16)];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.textColor = [UIColor colorWithHex:0xff737272];
    _timeLabel.font = [UIFont fontWithName:kFontNameHelvetica size:16];
    [self addSubview:_timeLabel];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 104, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLineImageFile ofType:nil]]];
    [self addSubview:_lineImageView];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)bindData:(RCChangePointsExtraItem *)dataModel{
    if (nil == dataModel) {
        return;
    }
    
    _themeNameLabel.text = [NSString stringWithFormat:@"点评（共%@条）",dataModel.changeNum];
    _userNameLabel.text = dataModel.userName;
    
    NSInteger score = dataModel.score;
    NSString *resourcePath = [[NSBundle mainBundle]resourcePath];
    UIImage *activeImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartActiveImageFile]];
    UIImage *inactiveImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartInActiveImageFile]];
    [_startImageView1 setImage:score > 0 ? activeImage : inactiveImage];
    [_startImageView2 setImage:score > 1 ? activeImage : inactiveImage];
    [_startImageView3 setImage:score > 2 ? activeImage : inactiveImage];
    [_startImageView4 setImage:score > 3 ? activeImage : inactiveImage];
    [_startImageView5 setImage:score > 4 ? activeImage : inactiveImage];
    
    _contentLabel.hidden = YES;
    CGFloat height = 62;
    
    if (![NSString stringIsNullOrEmpty:dataModel.content]) {
        _contentLabel.hidden = NO;
        _contentLabel.text = dataModel.content;
        CGSize size = [_contentLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(292, 2000) Leading:6];
        CGRect rect = _contentLabel.frame;
        rect.size.height = size.height;
        _contentLabel.frame = rect;
        
        height +=size.height;
    }
    
    _timeLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:dataModel.dateTime]) {
        _timeLabel.hidden = NO;
        _timeLabel.text = dataModel.dateTime;
        
        height +=3;
        CGRect rect = _timeLabel.frame;
        rect.origin.y = height;
        _timeLabel.frame = rect;
        height +=16;
    }
    
    height +=7;
    _lineImageView.frame = CGRectMake(0, height, 320, 1);
    
}

+(CGFloat)getCellHeight:(RCChangePointsExtraItem *)dataModel{
    if (nil == dataModel) {
        return 0.0f;
    }
    
    CGFloat height = 59;
    
    if (![NSString stringIsNullOrEmpty:dataModel.content]) {
        TTTAttributedLabel *label = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(14, 62, 292, 16)];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor colorWithHex:0xff737272];
        label.font = [UIFont systemFontOfSize:16];
        label.numberOfLines = 0;
        label.leading = 6;
        
        label.text = dataModel.content;
        CGSize size = [label.attributedText sizeWithConstrainedToSize:CGSizeMake(292, 2000) Leading:6];
        
        height +=3;
        height +=size.height;
        [label release];
    }
    
    if (![NSString stringIsNullOrEmpty:dataModel.dateTime]) {
        height +=19;
    }
    
    height += 8;
    return height;
}

@end

@interface RCChangePointsDetailChangeRecordCell()

@property(nonatomic,retain)UILabel *themeNameLabel;
@property(nonatomic,retain)TTTAttributedLabel *contentLabel;
@property(nonatomic,retain)UILabel *timeLabel;

@end

@implementation RCChangePointsDetailChangeRecordCell

@synthesize themeNameLabel = _themeNameLabel;
@synthesize contentLabel = _contentLabel;
@synthesize timeLabel = _timeLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
    }
    return self;
}

-(void)dealloc{
    
    self.themeNameLabel = nil;
    self.contentLabel = nil;
    self.timeLabel = nil;
    [super dealloc];
}

-(void)createPlaceHolderView{
    
    _themeNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 7, 220, 16)];
    _themeNameLabel.backgroundColor = [UIColor clearColor];
    _themeNameLabel.textColor = [UIColor colorWithHex:0xfffe8301];
    _themeNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    [self addSubview:_themeNameLabel];
    
    
    _contentLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(14, 26, 292, 16)];
    _contentLabel.backgroundColor = [UIColor clearColor];
    _contentLabel.textColor = [UIColor colorWithHex:0xff737272];
    _contentLabel.font = [UIFont systemFontOfSize:16];
    _contentLabel.numberOfLines = 0;
    _contentLabel.leading = 6;
    [self addSubview:_contentLabel];
    
    _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 45, 270, 16)];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.textColor = [UIColor colorWithHex:0xff737272];
    _timeLabel.font = [UIFont fontWithName:kFontNameHelvetica size:16];
    [self addSubview:_timeLabel];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)bindData:(RCChangePointsExtraItem *)dataModel{
    if (nil == dataModel) {
        return;
    }
    
    _themeNameLabel.text = [NSString stringWithFormat:@"兑换记录（共%@条）",dataModel.changeNum];
    
    
    _contentLabel.hidden = YES;
    CGFloat height = 26;
    
    if (![NSString stringIsNullOrEmpty:dataModel.userName]) {
        _contentLabel.hidden = NO;
        _contentLabel.text = [NSString stringWithFormat:@"用户%@兑换了一部",dataModel.userName];
        CGSize size = [_contentLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(292, 2000) Leading:6];
        CGRect rect = _contentLabel.frame;
        rect.size.height = size.height;
        _contentLabel.frame = rect;
        
        height +=size.height;
    }
    
    _timeLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:dataModel.dateTime]) {
        _timeLabel.hidden = NO;
        _timeLabel.text = dataModel.dateTime;
        
        height +=3;
        CGRect rect = _timeLabel.frame;
        rect.origin.y = height;
        _timeLabel.frame = rect;
    }
    
    
}

+(CGFloat)getCellHeight:(RCChangePointsExtraItem *)dataModel{
    if (nil == dataModel) {
        return 0.0f;
    }
    
    CGFloat height = 23;
    
    if (![NSString stringIsNullOrEmpty:dataModel.userName]) {
        TTTAttributedLabel *label = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(14, 62, 292, 16)];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor colorWithHex:0xff737272];
        label.font = [UIFont systemFontOfSize:16];
        label.numberOfLines = 0;
        label.leading = 6;
        
        label.text = [NSString stringWithFormat:@"用户%@兑换了一部",dataModel.userName];
        CGSize size = [label.attributedText sizeWithConstrainedToSize:CGSizeMake(292, 2000) Leading:6];
        
        height +=3;
        height +=size.height;
        [label release];
    }
    
    if (![NSString stringIsNullOrEmpty:dataModel.dateTime]) {
        height +=19;
    }
    
    height += 7;
    return height;
}

@end

@interface RCChangePointsDetailPictureCell()

@property(nonatomic,retain)UIImageView *contentImageView;
@property(nonatomic,retain)UIImageView *lineImageView;


@end

@implementation RCChangePointsDetailPictureCell

@synthesize contentImageView = _contentImageView;
@synthesize lineImageView = _lineImageView;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
    }
    return self;
}

-(void)dealloc{
    
    self.contentImageView = nil;
    self.lineImageView = nil;
    [super dealloc];
}

-(void)createPlaceHolderView{
    
    _contentImageView = [[UIImageView alloc]initWithFrame:CGRectMake(18, 10, 284, 285)];
    _contentImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:_contentImageView];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 299, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLineImageFile ofType:nil]]];
    [self addSubview:_lineImageView];
}

-(void)bindData:(RCChangePointsExtraItem *)dataModel{
    if (nil == dataModel || [NSString stringIsNullOrEmpty:dataModel.content]) {
        return;
    }
    [_contentImageView setImageWithURL:[NSURL URLWithString:dataModel.content] placeholderImage:nil];
}

+(CGFloat)getCellHeight:(RCChangePointsExtraItem *)dataModel{
    if (nil == dataModel || [NSString stringIsNullOrEmpty:dataModel.content]) {
        return 0.0f;;
    }
    return 300;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
